/*
 *   Copyright 1999-2016 Asiainfo Technologies(China),Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package com.asiainfo.redis.scheduling;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * @author william.xu
 * @version $Id: BaseJob.java,v 1.1 2013/06/18 09:12:20 xuwz Exp $
 * Created on 2013-5-21 下午4:24:58
 */
@DisallowConcurrentExecution
public class BaseJob extends QuartzJobBean {
	
	//父类QuartzJobBean通过BeanWrapper类的setPropertyValues注入以下属性

	//scheduler.getContext()(context.getScheduler().getContext())通过SchedulerFactoryBean的applicationContextSchedulerContextKey属性注入了ApplicationContext
	protected ApplicationContext applicationContext;
	
	//由于通过CronTriggerFactoryBean这个FactoryBean生成的CronTriggerImpl实例的jobDataMap中已经加入了jobDetail的属性
	//所以从getMergedJobDataMap中获取到了trigger的jobDataMap中的这个属性
	protected JobDetail jobDetail;
	
	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}

	public void setJobDetail(JobDetail jobDetail) {
		this.jobDetail = jobDetail;
	}

	public void executeInternal(JobExecutionContext context) throws JobExecutionException {
//		try {
//			SchedulerContext schedulerContext = context.getScheduler().getContext();
//			ApplicationContext applicationContext = (ApplicationContext)schedulerContext.get("applicationContext");
//		} catch (Exception e) {
//		}
//		System.out.println(context.getMergedJobDataMap().get("applicationContext"));
	}
}	